package com.doupi.partner.service.impl;

import java.util.List;

import org.apache.ibatis.session.RowBounds;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.doupi.partner.dal.OperationLogMapper;
import com.doupi.partner.dal.model.OperationLog;
import com.doupi.partner.service.OperationLogService;
import com.doupi.partner.util.Pagination;

@Service
public class OperationLogServiceImpl implements OperationLogService {
	private final OperationLogMapper operationLogMapper;

	@Autowired
	public OperationLogServiceImpl(OperationLogMapper operationLogMapper) {
		this.operationLogMapper = operationLogMapper;
	}

	public int deleteByPrimaryKey(Long id) {
		return operationLogMapper.deleteByPrimaryKey(id);
	}

	public int insert(OperationLog record) {
		record.setCreateTime(null);
		return operationLogMapper.insert(record);
	}

	public OperationLog selectByPrimaryKey(Long id) {
		return operationLogMapper.selectByPrimaryKey(id);
	}

	public int updateByPrimaryKeySelective(OperationLog record) {
		record.setCreateTime(null);
		return operationLogMapper.updateByPrimaryKeySelective(record);
	}

	public int countOperationLog(OperationLog operationLog) {
		return operationLogMapper.countOperationLog(operationLog);
	}

	public List<OperationLog> queryOperationLogs(OperationLog operationLog, RowBounds rowBounds) {
		return operationLogMapper.queryOperationLogs(operationLog, rowBounds);
	}

	public OperationLog selectOperationLogForUpdateByPrimaryKey(Long id) {
		return operationLogMapper.selectOperationLogForUpdateByPrimaryKey(id);
	}

	public Pagination<OperationLog, OperationLog> queryOperationLogs(Pagination<OperationLog, OperationLog> pagination) {
		int count = countOperationLog(pagination.getParam());
		pagination.setTotalCount(count);
		if (count > 0) {
			pagination.setRecords(queryOperationLogs(pagination.getParam(), new RowBounds(pagination.getOffset(), pagination.getLimit())));
		}
		return pagination;
	}
}
